<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <link rel="stylesheet" th:href="@{static/css/user.css}" type="text/css"></link>
</head>
<body>
<div class="header">
    <h1>用户列表</h1>
</div>
<div class="add-button-wrapper">
    <a class="add-button" th:href="@{/toAdd}">新增用户</a>
</div>
<table>
    <thead>
    <tr>
        <th>编号</th>
        <th>用户名</th>
        <th>性别</th>
        <th>邮箱</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>

    <tr th:each="user : ${users}">
        <td th:text="${user.id}"></td>
        <td th:text="${user.username}"></td>
        <td th:text="${user.sex == 1 ? '男' : '女'}"></td>
        <td th:text="${user.email}"></td>
        <td>
            <!--            将 id 传过去，进行修改-->
            <a th:href="@{'/user/'+ ${user.id}}">修改</a>
            <a th:href="@{'/user/'+ ${user.id}}" onclick="del(event)">删除</a>
        </td>
    </tr>

    </tbody>
</table>
<!--为删除操作准备一个form表单，点击删除时提交form表单-->
<div style="display: none">
    <form method="post" id="delForm">
        <!--        删除是 delte 请求-->
        <input type="hidden" name="_method" value="delete"/>
    </form>
</div>

<script>
    function del(event) {
        // 获取表单
        let delForm = document.getElementById("delForm");
        // 设置表单action ev
        delForm.action = event.target.href;
        if (window.confirm("您确定要删除吗？")) {
            // 提交表单
            delForm.submit();
        }
        // 阻止超链接默认行为
        event.preventDefault();
    }
</script>


<!--java.lang.IllegalArgumentException: Name for argument of type [java.lang.Long] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag.-->

</body>
</html>